package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.model.QuestionBean;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.widget.XImageLoader;

/**
 * Created by itboye on 2017/3/9.
 */

public class HeadGridAdapter extends BaseAdapter {
    Context context;
    private QuestionBean  list;
    boolean ichat;

    int selectedPosition;
    public HeadGridAdapter(Context context, QuestionBean list) {
        this.context = context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.getAvatar().size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public void clearSelection(int position,boolean ichat) {
        selectedPosition = position;
        this.ichat=ichat;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHouder houder;
        if(convertView==null){
            houder=new ViewHouder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_head_gridbiew, null);
            houder.img= (ImageView) convertView.findViewById(R.id.imgheadPres);
            houder.imageView= (ImageView) convertView.findViewById(R.id.imageView);
            convertView.setTag(houder);
        }else{
            houder= (ViewHouder) convertView.getTag();
        }
        if(selectedPosition==position){
            houder.imageView.setVisibility(View.VISIBLE);
            houder.imageView.setBackgroundResource(R.drawable.selete_yelow);

        }else{
            houder.imageView.setBackgroundResource(R.drawable.head_label);
        }

        Log.d("IMAGE_HEAD",list.getAvatar().get(position).getAvatar().get(0));
        for (int i=0;i<list.getAvatar().get(position).getAvatar().size();i++){
            Log.d("IMAGE_HEADsssss",list.getAvatar().get(position).getAvatar().get(i));
            XImageLoader.load(Const.IMAGE_HEAD+list.getAvatar().get(position).getAvatar().get(i),houder.img);
        }


        return convertView;
    }
    public class  ViewHouder{
        ImageView img,imageView,imageViews;
    }
}

